package de.alfenory.autobill.test.lib;

import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author alefen
 */
public class testObject {
    
    private static final Logger log = Logger.getLogger(testObject.class.getName());
    
    public static void testObjects(String methods[], Object object, Object testobject) throws Exception {
        for(String method : methods) {
            Object object1 = object.getClass().getMethod(method).invoke(object, (Object[]) null);
            Object object2 = object.getClass().getMethod(method).invoke(testobject, (Object[]) null);
            if(!object1.equals(object2)) {
                throw new NotEqualException("Object."+method+": "+object1+" is not equal to Testobject."+method+"():"+object2);
            }
            else {
                log.log(Level.FINEST, "{0}={1}", new Object[]{object1, object2});
            }
            
        }
    }
    
    public static void main(String args[]) {
        Integer val1 = new Integer(1);
        Integer val2 = new Integer(1);
        String methods[] = {"intValue"};
        try {
            testObjects(methods, val1, val2);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        
    }
    
    public static void testListObject(String methods[], List<?> objectList, List<?> testObjectList) throws Exception {
        String messages = "";
        for(int i=0;i<objectList.size();i++) {
            log.log(Level.FINE, "{0} line", i);
            System.out.println(i+".line");
            try {
                testObjects(methods, objectList.get(i), testObjectList.get(i));
            }
            catch(Exception e) {
                messages += e.getMessage()+"\n";
            }
        }
        if(objectList.size()!=testObjectList.size()) {
            messages += "Array size differ "+objectList.size()+"!="+testObjectList.size();
        }
        if(messages.length()!=0) {
            throw new NotEqualException(messages);
        }
    }
    
}
